<?php

namespace app\common\controller;
use Qiniu\Auth;
/**
 * 七牛云
 * 
 */
class Qiniu
{   
    private  $accessKey = 'tKSVBVtMhpePPIFA8A1QuA1Cy4R29Ab0WsBoeYmT';
    private  $secretKey = 'vqRJYEONSeW4nS2gs7xWaK5bm3KbZ5D-ErWZWRlS';
    private  $auth;
    public   $bucket  = 'myvideo';

    // 初始化签权对象
    function initialize()
    {
        $this->$auth = new Auth($this->$accessKey, $this->$secretKey);
    }

    public function down()
    {
        // 私有空间中的外链 http://<domain>/<file_key>
        $baseUrl = 'http://if-pri.qiniudn.com/qiniu.png?imageView2/1/h/500';
        // 对链接进行签名
        $signedUrl = $auth->privateDownloadUrl($baseUrl);
        echo $signedUrl;
    }

    public function getFileLists()
    {
        $accessKey = $this->$accessKey;
        $secretKey = $this->$secretKey;
        $bucket    =  $this->$bucket;
        $auth      = $this->$auth;
        
        $bucketManager = new BucketManager($auth);
        // 要列取文件的公共前缀
        $prefix = '';
        // 上次列举返回的位置标记，作为本次列举的起点信息。
        $marker = '';
        // 本次列举的条目数
        $limit = 100;
        $delimiter = '/';
        // 列举文件
        list($ret, $err) = $bucketManager->listFiles($bucket, $prefix, $marker, $limit, $delimiter);
        if ($err !== null) {
            echo "\n====> list file err: \n";
            var_dump($err);
        } else {
            if (array_key_exists('marker', $ret)) {
                echo "Marker:" . $ret["marker"] . "\n";
            }
            echo "\nList Iterms====>\n";
            //var_dump($ret['items']);
        }
    }

        

}